-- 战势技能
local LuaZhanshi = fk.CreateSkill{
  name = "LuaZhanshi",
  tags = { Skill.Permanent },
}

Fk:loadTranslationTable{
  ["LuaZhanshi"] = "战势",
    ["#ZSthunder__slash-use"] = "战势：你可以使用使用两张「雷杀」。（第%arg张，共2张）",
  ["@zhanshi"] = "<font color='#f70069'>战势值：</font>",
  ["@quanbing"] = "<font color='#6b002d'>权柄数：</font>",
  [":LuaZhanshi"] = "持恒技，当你造成或受到伤害时，你获得10点“战势”标记，你的“战势”标记上限为100，每当你“战势”标记为100时你清空“战势”获得1点“权柄”标记并视为使用两张「雷杀」。（你的“权柄”上限为10）",
}

LuaZhanshi:addEffect(fk.Damage, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(LuaZhanshi.name) and data.from and data.from == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    
    -- 获得10点战势
    local zhanshi = player:getMark("@zhanshi") or 0
    zhanshi = math.min(zhanshi + 10, 100)
    room:setPlayerMark(player, "@zhanshi", zhanshi)
    
    -- 如果战势达到100，处理权柄和雷杀
    if zhanshi == 100 then
      -- 清空战势
      room:setPlayerMark(player, "@zhanshi", 0)
      
      -- 获得权柄(最多10点)
      local quanbing = player:getMark("@quanbing") or 0
      quanbing = math.min(quanbing + 1, 10)
      room:setPlayerMark(player, "@quanbing", quanbing)
      for i = 1, 2 do
        if player.dead or not room:askToUseVirtualCard(player, {
            name = "thunder__slash",
            skill_name = LuaZhanshi.name,
            prompt = "#ZSthunder__slash-use:::" .. i,
            extra_data = {
                bypass_times = true,
                extraUse = true,
            },
        }) then
            break
        end
      end
    end
  end,
})

LuaZhanshi:addEffect(fk.Damaged, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(LuaZhanshi.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    
    -- 获得10点战势
    local zhanshi = player:getMark("@zhanshi") or 0
    zhanshi = math.min(zhanshi + 10, 100)
    room:setPlayerMark(player, "@zhanshi", zhanshi)
    
    -- 如果战势达到100，处理权柄和雷杀
    if zhanshi == 100 then
      -- 清空战势
      room:setPlayerMark(player, "@zhanshi", 0)
      
      -- 获得权柄(最多10点)
      local quanbing = player:getMark("@quanbing") or 0
      quanbing = math.min(quanbing + 1, 10)
      room:setPlayerMark(player, "@quanbing", quanbing)
      
      for i = 1, 2 do
        room:askToUseVirtualCard(player, {
            name = "thunder__slash",
            skill_name = LuaZhanshi.name,
            prompt = "#ZSthunder__slash-use:::" .. i,
            extra_data = {
                bypass_times = true,
                extraUse = true,
            },
        })
      end
    end
  end,
})

  return LuaZhanshi